//
//  HLBlackCell.m
//  YueYue
//
//  Created by hulu001 on 2023/5/19.
//

#import "HLBlackCell.h"
#import "HLUserOptionRequest.h"
#import "HLBlackListViewController.h"

@interface HLBlackCell ()

@property (nonatomic, strong) UIImageView *avatarView;
@property (nonatomic, strong) UILabel *nicknameLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) QMUIButton *removeButton;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HLBlackCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = UIColorWhite;
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    self.avatarView = [[UIImageView alloc] init];
    _avatarView.layer.cornerRadius = 24;
    _avatarView.layer.masksToBounds = YES;
    _avatarView.image = [HLUIHelper avatarPlaceholder];
    [self.contentView addSubview:_avatarView];
    [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(48);
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(12);
        make.bottom.mas_equalTo(-12);
    }];
    
    self.nicknameLabel = [[UILabel alloc] init];
    _nicknameLabel.textColor = HLTextColor1;
    _nicknameLabel.text = @"聊人生阿姨有没有啊";
    _nicknameLabel.font = UIFontMake(15);
    [self.contentView addSubview:_nicknameLabel];
    [_nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_avatarView.mas_right).offset(12);
        make.centerY.mas_equalTo(0);
    }];
    
    
    self.removeButton = [[QMUIButton alloc] init];
    [_removeButton setTitle:@"移除" forState:UIControlStateNormal];
    [_removeButton setTitleColor:UIColorWhite forState:UIControlStateNormal];
    [_removeButton setCornerRadius:14];
    [_removeButton setContentEdgeInsets:UIEdgeInsetsMake(6, 12, 6, 12)];
    [_removeButton setBackgroundColor:HLMainColor];
    [_removeButton.titleLabel setFont:UIFontMediumMake(12)];
    [_removeButton addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_removeButton];
    [_removeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-16);
    }];
    
    self.lineView = [[UIView alloc] init];
    _lineView.backgroundColor = HLLineColor;
    [self.contentView addSubview:_lineView];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.5);
        make.left.right.bottom.mas_equalTo(0);
    }];
}


- (void)setModel:(HLFriendsModel *)model
{
    _model = model;
    [_avatarView sd_setImageWithURL:[NSURL URLWithString:model.fuAvatar] placeholderImage:[HLUIHelper avatarPlaceholder]];
    [_nicknameLabel setText:model.fuNickname];
}

- (void)removeAction
{
    MJWeakSelf
    [HLUIHelper blackWithUserId:_model.fuId black:YES callback:^(BOOL isConfirm) {
        if (isConfirm){
            HLBlackListViewController *blackVC = (HLBlackListViewController *)weakSelf.qmui_viewController;
            [blackVC.datasources removeObject:self.model];
            [weakSelf.qmui_tableView reloadData];
        }
    }];
}


@end
